<?php
//根据ID获得分类名
function getCategoryName($id){
	if (empty ( $id )) {
		return '顶级分类';
	}
	$Category = D ( "Category" );
	$list = $Category->getField ( 'id,title' );
	$name = $list [$id];
	return $name;
}
//根据ID获得模型名
function getModuleById($id){
	$Category = D ( "Category" );
	$list = $Category->getField ( 'id,module' );
	$module = $list [$id];
	return $module;
}
//根据ID获得用户名
function getUserName($id){
	if (empty ( $id )) {
		return '游客';
	}
	$User = D ( "User" );
	$list = $User->getField ( 'id,nickname' );
	$name = $list [$id];
	return $name;
}
//根据ID获得文章标题
function getArticleById($id){
	$list = D('Article')->getField('id,title');
	$module = $list[$id];
	return $module;
}
//根据ID获得手机型号
function getPhoneTypeById($id){
	$list = D('PhoneType')->getField('id,title');
	$module = $list[$id];
	return $module;
}
//根据ID获得系统版本号
function getSystemVerById($id){
	$list = D('SystemVer')->getField('id,title');
	$module = $list[$id];
	return $module;
}
//根据ID获得频道Action
function getChannelActionById($id){
	$list = D('Channel')->getField('id,action');
	$module = $list[$id];
	return $module;
}
//获取手机型号列表
function getPhoneTypeList($phonetype){
	if($phonetype){
		$result = D('PhoneType')->where('status = 1')->find($phonetype);
		if($result['pid'] == 0){
			$results = D('PhoneType')->where('status = 1 and pid = '.$result['id'])->select();
			if(is_array($results)){
				foreach($results as $val) $ary[] = $val['id'];
			}
			//获取手机型号
			$PhoneType = D('PhoneType')->where('status = 1 and pid = '.$phonetype)->select();
			$PhoneType['map'] = array('in' , $ary);
		}else{	
			//获取手机型号
			$PhoneType = D('PhoneType')->where('status = 1 and pid = '.$result['pid'])->select();
			$PhoneType['map'] = array('eq' , $phonetype);
		}
	}
	return $PhoneType;
}
//获取系统版本列表
function getSystemVerList(){
	$resutl = D('SystemVer')->where('status = 1')->select();
	return $resutl;	
}
//获取频道id
function getCheannelId($channelname){
	$list = D('Channel')->where("status = 1 AND action = '$channelname'")->find();
	$module = $list['id'];
	return $module;
}
//根据ID获得频道名
function getChannelName($id){
	$Channel = D ( "Channel" );
	$list = $Channel->getField ( 'id,title' );
	$name = $list [$id];
	return $name;
}
//根据ID获得分类的rewrite
function getCateRewrite($id){
	$rewrite = D('Category')->where('status = 1 AND id = '.$id)->getField('rewrite');
	if(!$rewrite){
		$rewrite = 'c/id/'.$id;
	}
	return $rewrite;
}
//根据分类ID获得频道Action
function getChannelActionByCid($id){
	$Category = D("Category");
	$Channel = D("Channel");
	$ChannelId = $Category->where('status = 1 AND id = '.$id)->getField('channelid');
	$ChannelAction = $Channel->where('status = 1 AND id = '.$ChannelId)->getField('action');
	return $ChannelAction;
}
?>